home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ML_3DROT.ZIP / SOURCES / FIG4.PAS < prev    next >
Pascal/Delphi Source File  |  1996-12-26  |  3KB  |  132 lines

  1. {
  2.   Example of using the 3D "engine", by Maple Leaf, 1996
  3.  
  4.   This code is freeware. If you find it useful, feel free to do whatever
  5.   you want with it, with only one condiion: give some small greetings to
  6.   Maple Leaf in your productions that use parts of it.
  7.  
  8.                                                         Maple Leaf, '96
  9.  
  10.   btw, I'm too lazy to write down kilos of comments...   :-)
  11. }
  12. uses xmode,crt,engine3d;
  13.  
  14. var a,b:word;
  15.     pal:array[byte] of record r,g,b:byte end;
  16.     capag,cvpag : word;
  17.     dd:integer;
  18.     coord:array[0..730] of record x,y,z:integer end;
  19.     RealMapping : Boolean;
  20.     ch:char;
  21.     MaxPnt:word;
  22.     RotStep,TiltStep:longint;
  23.  
  24. Procedure GenFig;
  25. var cnt,i,j,k:word;
  26. begin
  27.   cnt:=0;
  28.   for i:=0 to 25 do
  29.     for j:=0 to 25 do begin
  30.       with coord[cnt] do begin
  31.         x:=i shl 2;
  32.         y:=j shl 2;;
  33.         z:=0;
  34.       end;
  35.       inc(cnt);
  36.     end;
  37.   MaxPnt:=cnt
  38. end;
  39.  
  40. Procedure PuneFig;
  41. var i:integer; cnt:word;
  42. begin
  43.   cnt:=0;
  44.   {xvwait;}
  45.   xclrvpage(capag);
  46.   for i:=0 to MaxPnt-1 do begin
  47.     _3dx:=coord[i].x+60;
  48.     _3dy:=coord[i].y;
  49.     _3dz:=coord[i].z+30;
  50.     asm
  51.        cmp RealMapping,1
  52.        je @1
  53.        call IntMapCoordinates
  54.        jmp @2
  55.     @1:call MapCoordinates
  56.     @2:
  57.     end;
  58.     xvplot(_2dx,_2dy,(i+2) shr 1,capag);
  59.   end;
  60. end;
  61.  
  62. Procedure IntroText;
  63. begin
  64.   Writeln('3D Figure, by Maple Leaf, 1996.');
  65.   Writeln(#13#10,' Hot keys are:'#13#10);
  66.   Writeln('   <M>     - Change mapping method (float/integer)');
  67.   Writeln('   <Left>  - Decrement horizontal speed of rotation');
  68.   Writeln('   <Right> - Increment horizontal speed of rotation');
  69.   Writeln('   <Up>    - Increment vertical speed of rotation');
  70.   Writeln('   <Down>  - Decrement vertical speed of rotation');
  71.   Writeln(#13#10'Press a key to start ...');
  72.   Readkey;
  73. end;
  74.  
  75. begin
  76.   ClrScr;
  77.   GenFig;
  78.   IntroText;
  79.   xinitvideo(0);
  80.   xclrvram;
  81.   for a:=1 to 255 do with pal[a] do begin
  82.     r:=Trunc(63*a/255);
  83.     g:=Trunc(40);
  84.     b:=Trunc(63-63*a/255);
  85.   end;
  86.   xsetpalette(@pal);
  87.   ZoomFactor:=500;
  88.   Perspective:=True;
  89.   SetObserverPosition(0,20,500);
  90.   SetAngles(0,20);
  91.   capag:=0;
  92.   cvpag:=3;
  93.   dd:=10;
  94.   RealMapping:=false;
  95.   RotStep:=3;
  96.   TiltStep:=0;
  97.   repeat
  98.    repeat
  99.  
  100.     xvwait;
  101.     xsetvpage(cvpag);
  102.  
  103.     RotAngle:=RotAngle+RotStep;
  104.     TiltAngle:=TiltAngle+TiltStep;
  105.     if RotAngle>359 then RotAngle:=360-RotAngle;
  106.     if RotAngle<0 then RotAngle:=360+RotAngle;
  107.     if TiltAngle>359 then TiltAngle:=360-TiltAngle;
  108.     if TiltAngle<0 then TiltAngle:=360+TiltAngle;
  109.     {SetAngles(RotAngle,TiltAngle);}
  110.  
  111.     PuneFig;
  112.  
  113.     inc(capag); if capag>3 then capag:=0;
  114.     inc(cvpag); if cvpag>3 then cvpag:=0;
  115.  
  116.    until keypressed;
  117.    ch:=readkey;
  118.    case UpCase(ch) of
  119.      'M': { Mapping mode } RealMapping:=not RealMapping;
  120.      #0: begin
  121.        ch:=readkey;
  122.        case ch of
  123.          #72: {Up}    inc(RotStep);
  124.          #80: {Down}  dec(RotStep);
  125.          #75: {Left}  dec(TiltStep);
  126.          #77: {Right} inc(TiltStep);
  127.        end;
  128.      end;
  129.    end;
  130.   until ch=#27;
  131.   textmode(25);
  132. end.